package com.dhh.sky.widget;

import com.dhh.sky.activity.BasicActivity;
import android.view.MotionEvent;
import android.view.View;

public class SwipeDetector implements View.OnTouchListener {
	private BasicActivity context;
	static final int MIN_DISTANCE = 200;
	private float downX, downY, upX, upY;

	public SwipeDetector(BasicActivity activity) {
		this.context = activity;
	}

	public void onRightToLeftSwipe() {
	}

	public void onLeftToRightSwipe() {
	}

	public void onTopToBottomSwipe() {
	}

	public void onBottomToTopSwipe() {
	}

	public boolean onTouch(View v, MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN: {
			downX = event.getX();
			downY = event.getY();
			return true;
		}
		case MotionEvent.ACTION_UP: {
			upX = event.getX();
			upY = event.getY();

			float deltaX = downX - upX;
			float deltaY = downY - upY;

			// swipe horizontal?
			if (Math.abs(deltaX) > MIN_DISTANCE) {
				// left or right
				if (deltaX < 0) {
					this.onLeftToRightSwipe();
					return true;
				}
				if (deltaX > 0) {
					this.onRightToLeftSwipe();
					return true;
				}
			} else {
				return false; // We don't consume the event
			}

			// swipe vertical?
			if (Math.abs(deltaY) > MIN_DISTANCE) {
				// top or down
				if (deltaY < 0) {
					this.onTopToBottomSwipe();
					return true;
				}
				if (deltaY > 0) {
					this.onBottomToTopSwipe();
					return true;
				}
			} else {
				return false; // We don't consume the event
			}

			return true;
		}
		}
		return false;
	}

}
